class GameMap extends AcGameObject {
    constructor(playground) {
        super();
        this.playground = playground;
        this.$canvas = $(`<canvas tabindex=0></canvas>`);
        this.ctx = this.$canvas[0].getContext('2d');
        this.ctx.canvas.width = this.playground.width;
        this.ctx.canvas.height = this.playground.height;
        this.playground.$playground.append(this.$canvas);

         if (this.playground.$playground.find('.ac-game-exit-button').length === 0) {
            this.$exit_button = $(`<button class="ac-game-exit-button">退出</button>`);
            this.playground.$playground.append(this.$exit_button);
        }
    }

    start() {
        this.$canvas.focus();
        this.add_listening_events(); // 添加这行来确保事件监听器被注册
    }
    add_listening_events() {
        let outer = this;
        this.$exit_button.click(function() {
             // 清除 DOM 元素
            outer.$canvas.remove();
            outer.$exit_button.remove();
            // 隐藏游戏界面并显示菜单界面
            outer.playground.hide();
            outer.playground.root.menu.show();
        });
    }
    resize() {
        this.ctx.canvas.width = this.playground.width;
        this.ctx.canvas.height = this.playground.height;
        this.ctx.fillStyle = "rgba(0, 0, 0, 1)";
        this.ctx.fillRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
    }

    update() {
        this.render();
    }

    render() {
        this.ctx.fillStyle = "rgba(0, 0, 0, 0.2)";
        this.ctx.fillRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
    }
}
